<form lay-filter="modelBizRelationVideoForm" class="layui-form model-form" style="padding: 5px;">
	<input name="bizVideo.id" type="hidden" value="#(bizVideo?bizVideo.id:'')" />
	<input name="bizVideo.sceneId" type="hidden" value="#(sceneId)"/>
	<input name="bizVideo.objId" type="hidden" value="#(objId)"/>
	<input name="bizVideo.event" type="hidden" value="#(event)"/>
	<table id="modelBizVideoFormTable" class="formTable">
		<tr>
			<td>* 名称</td>
			<td colspan="3" style="text-align: left;">
				<input name="bizVideo.name" placeholder="请输入名称" type="text" class="layui-input" lay-verType="tips" lay-verify="required"
				 required value="#(bizVideo?bizVideo.name:'')" />
			</td>
		</tr>
		<tr>
			<td>标识</td>
			<td colspan="3" style="text-align: left;">
				<input name="bizVideo.code" placeholder="请输入标识" type="text" class="layui-input" lay-verType="tips" value="#(bizVideo?bizVideo.code:'')" />
			</td>
		</tr>
		<!-- <tr>
			<td>分类</td>
			<td colspan="3" style="text-align: left;">
				<input id="classifyIdForVideo" lay-filter="classifyIdForVideo" name="bizVideo.classifyId" class="layui-input" type="text"
				 placeholder="输入关键字" value="#(bizVideo?bizVideo.classifyId:'')" />
			</td>
		</tr> -->
		<tr>
			<td>* 服务类型</td>
			<td colspan="3" style="text-align: left;">
				<select id="videoSelectId" name="bizVideo.type" lay-filter="bizVideoType"  lay-verify="required" required>
		        	<option value="WEBRTC" #if(bizVideo && bizVideo.type=='WEBRTC')  selected #end>webrtc服务</option>
		        	<option value="FILE" #if(bizVideo && bizVideo.type=='FILE')  selected #end>mp4视频文件</option>
		      	</select>
			</td>
		</tr>
	</table>
</form>
<!-- 视频文件地址 -->
<script type="text/html" id="modelVideoFile">
	<tr class="file">
		<td>视频Url</td>
		<td colspan="3" style="text-align: left;">
			<input name="bizVideo.url" placeholder="请输入视频Url" type="text" class="layui-input" lay-verType="tips" lay-verify="required"
			 required value="#(bizVideo?bizVideo.url:'')"  />
		</td>
	</tr>
	<tr class="file">
		<td colspan="4">
			<button class="layui-btn" lay-filter="modelSubmitBizVideoForm" lay-submit>保存</button>
		</td>
	</tr>
</script>

<!-- rtc参数 -->
<script type="text/html" id="modelVideoWebrtc">
	<tr class="webrtc">
		<td>* ip</td>
		<td colspan="3" style="text-align: left;">
			<input name="bizVideo.ip" placeholder="请输入ip" type="text" class="layui-input" lay-verType="tips" lay-verify="required"
			 required value="#(bizVideo?bizVideo.ip:'')"   />
		</td>
	</tr>
	<tr class="webrtc">
		<td>* 用户名</td>
		<td colspan="3" style="text-align: left;">
			<input name="bizVideo.username" placeholder="请输入用户名" type="text" class="layui-input" lay-verType="tips" lay-verify="required"
			 required value="#(bizVideo?bizVideo.username:'')" />
		</td>
	</tr>
	<tr class="webrtc">
		<td>* 密码</td>
		<td colspan="3" style="text-align: left;">
			<input name="bizVideo.password" placeholder="请输入密码" type="text" class="layui-input" lay-verType="tips" lay-verify="required"
			 required value="#(bizVideo?bizVideo.password:'')" />
		</td>
	</tr>
	<tr class="webrtc">
		<td>* 端口</td>
		<td colspan="3" style="text-align: left;">
			<input name="bizVideo.port" placeholder="请输入端口" type="text" class="layui-input" value="8000" lay-verType="tips" lay-verify="required"
			 required value="#(bizVideo?bizVideo.port:'')"  />
		</td>
	</tr>
	<tr class="webrtc">
		<td>通道号</td>
		<td colspan="3" style="text-align: left;">
			<input name="bizVideo.channelNum" placeholder="请输入通道号" type="text" class="layui-input" lay-verType="tips" value="#(bizVideo?bizVideo.channelNum:'')" />
		</td>
	</tr>
	<tr class="webrtc">
		<td>* 设备类型</td>
		<td colspan="3" style="text-align: left;">
			<select name="bizVideo.deviceType" lay-filter="deviceType" lay-verify="required" required>
				<option value="HK/IPC" #if(bizVideo && bizVideo.deviceType=='HK/IPC')  selected #end>摄像头</option>
				<option value="HK/NVR" #if(bizVideo && bizVideo.deviceType=='HK/NVR')  selected #end>硬盘录像机</option>
			</select>
		</td>
	</tr>
	<tr class="webrtc">
		<td>* 设备状态</td>
		<td colspan="3" style="text-align: left;">
			<select name="bizVideo.deviceStatus" lay-filter="deviceStatus" lay-verify="required" required>
				<option value="0" #if(bizVideo && bizVideo.deviceStatus=='0')  selected #end>在线</option>
				<option value="1" #if(bizVideo && bizVideo.deviceStatus=='1')  selected #end>离线</option>
			</select>
		</td>
	</tr>
	<tr class="webrtc">
		<td>* 监控点类型</td>
		<td colspan="3" style="text-align: left;">
			<select name="bizVideo.monitorType" lay-filter="monitorType" lay-verify="required" required>
				<option value="bolt" #if(bizVideo && bizVideo.monitorType=='bolt')  selected #end>枪机</option>
				<option value="ballhead" #if(bizVideo && bizVideo.monitorType=='ballhead')  selected #end>球机</option>
				<option value="cloud-bolt" #if(bizVideo && bizVideo.monitorType=='cloud-bolt')  selected #end>云台枪机</option>
			</select>
		</td>
	</tr>
	<tr class="webrtc">
		<td>* 协议类型</td>
		<td colspan="3" style="text-align: left;">
			<select name="bizVideo.protocol" lay-filter="protocol" lay-verify="required" required>
				<option value="rtsp" #if(bizVideo && bizVideo.protocol=='rtsp')  selected #end>rtsp</option>
				<option value="onvif" #if(bizVideo && bizVideo.protocol=='onvif')  selected #end>onvif</option>
			</select>
		</td>
	</tr>
	<tr class="webrtc">
		<td>安装地址</td>
		<td colspan="3" style="text-align: left;">
			<input name="bizVideo.address" placeholder="请输入安装地址" type="text" class="layui-input" lay-verType="tips" value="#(bizVideo?bizVideo.address:'')" />
		</td>
	</tr>
	<tr class="webrtc">
		<td colspan="4">
			<button class="layui-btn" lay-filter="modelSubmitBizVideoForm" lay-submit>保存</button>
		</td>
	</tr>
</script>
<!-- js部分 -->
<script>
layui.use(['layer', 'config','form', 'table', 'util', 'admin', 'treeSelect','upload','step'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var config = layui.config;
        var step = layui.step;
        var upload = layui.upload;
        var treeSelect = layui.treeSelect;
        var url = 'biz/video/save';
        #if(bizVideo)
        	#if(bizVideo.type=='WEBRTC')
            	$('#modelBizVideoFormTable').append($('#modelVideoWebrtc').html());
        	#else
        		$('#modelBizVideoFormTable').append($('#modelVideoFile').html());
        	#end
        #else
        	$('#modelBizVideoFormTable').append($('#modelVideoWebrtc').html());
        #end
        
        form.on('select(bizVideoType)', function(data){
    		if(data.value=='WEBRTC'){
    			if($('.webrtc').length>0)return;
    			$('.file').remove();
    			$('#modelBizVideoFormTable').append($('#modelVideoWebrtc').html());
    			form.render('select'); 
    		}else{
    			if($('.file').length>0)return;
    			$('.webrtc').remove();
    			$('#modelBizVideoFormTable').append($('#modelVideoFile').html());
    		}
        });
        
        form.on('submit(modelSubmitBizVideoForm)', function (data) {
       	 	layer.load(2);
            var res = common_ajax.ajaxFunc("#(ctx)/biz/video/save", data.field, null);
            console.log(res);
            layer.closeAll('loading');
            if (200==res.code) {
            	layer.close(dIndex);
            	layer.msg(res.message, {icon: 1});
            	relationtVideoTb.reload({}, 'data');
              	//视频推送
              	if(res.data.type=='FILE')return false;
              	//addVideo(res.data);
            } else {
                layer.msg(res.message, {icon: 2});
            }
            return false;
        });
        
		//添加视频
        function addVideo(data){
        	var dataJson={};
        	dataJson.dev={
        		"group":"",
        		"id":data.id,
        		"name":data.name,
        		"type":data.deviceType,
        		"protocol":data.protocol,
        		"ip":data.ip,
        		"port":data.port,
        		"usr":data.username,
        		"pwd":data.password
        	}
        	if(data.type=='HK/NVR'){
        		dataJson.channel={
               		"group":"",
                	"id":data.id,
                	"name":data.name,
                	"video": "",
            		"options": "",
                	"channelNum":data.channelNum
               	}
        	}
        	var res = common_ajax.ajaxFunc(rtcSerUrl+'/api/addMedia', JSON.stringify(dataJson), "json", null);
            layer.closeAll('loading');
            if (res.code==0) {
            	//添加成功更新视频数据同步状态
            	var res = common_ajax.ajaxFunc('#(ctx)/biz/video/updataSynStatus', {id:data.id,status:'1'}, "json", null);
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }
    });
</script>